<?php
defined( '_VALID_MOS' ) or die('<script>window.location.href="http://www.kinifurniture.com";</script>');

$adm_functions->is_admin_login();

$icon_description='
<table><tr><td>
	<table cellspacing="0" cellpadding="4" border="0" align="center">
		<tr align="center">
			<td>
				<img src="show_files/publish1.png" width="12" height="12" border="0" alt="Pending" />
			</td>
			<td>
				News is <u>inactive</u> |
			</td>
			<td>
				<img src="show_files/tick.png" width="12" height="12" border="0" alt="Visible" />
			</td>
			<td>
				News is <u>active</u>  |
			</td>
			<td>
				<img src="show_files/delete.png" border="0" alt="Visible" />
			</td>
			<td>
				<u>Delete</u> Gallery
			</td>
		</tr>
	</table>
</td></tr><tr><td align="center">
	<table cellspacing="0" cellpadding="4" border="0" align="center">
		<tr align="center">
			<td align="center">
				<i>Click on icon to toggle state or execute command.</i>
			</td>
		</tr>
	</table>
</td></tr></table>
';
$adm_menu='
<table width="100%" class="menubar" cellpadding="0" cellspacing="0" border="0">
<tr>
	<td class="menudottedline" width="40%">
		<div class="pathway"><img border="0" src="assets/admin/'.$SITE_LOGO_ADMIN.'"/></div>	</td>
	<td class="menudottedline" align="right">
		<table cellpadding="0" cellspacing="0" border="0" id="toolbar">
			<tr valign="middle" align="center">
				<td>&nbsp;</td>
				<td>
					<a class="toolbar" href="admin.php?show=index">
					<img src="show_files/home.png" alt="Home" name="home" title="Home" align="middle" border="0" />				<br />Home</a>
				</td>
				<td>&nbsp;</td>
				<td>
					<a class="toolbar" href="admin.php?show=album_manager">
					<img src="show_files/back.png"  alt="Albums" name="albums" title="albums" align="middle" border="0" /><br />Albums</a>
				</td>
				<td>&nbsp;</td>
				<td>
					<a class="toolbar" href="admin.php?show=add_gallery&coll='.$coll.'" >
					<img src="show_files/new_f200.png"  alt="New" name="new" title="New" align="middle" border="0" />				<br />New</a>
				</td>
			</tr>
		</table>
	</td>
</tr>
</table>

<br />
';
if($action=="do_delete"){
	$qrydel="select image from albumdetail where id_gambar=$id";
	$selectdel=$dbh->query($qrydel);
	while($sqldel=mysql_fetch_object($selectdel))
	{
		$img_name=$sqldel->image;
		if ($img_name!='')
		@unlink("assets/albumdetail/".$img_name);
		$dbh->query("delete from albumdetail where id_gambar=$id");
		echo '<script>window.location.href="admin.php?show=gallery_manager";</script>';
	}
}
if($action=="") $action="list";

if($action=="list"){

if(!$page_no)
	$page_no=1;
$MAX=9;
$lastrow=$MAX+$page_no;
if(!next_page)
	$next_page=1;
$next_page=$next_page+1;

$imgSr=$page_no;

if(!$coll)
$coll='all';

$selected='';

if($coll=='all')
{
	$condition="";
	$selected='selected';
} else {
	$condition="where id_album=".$coll;
}

	$sort_album='
		<select name="coll" class="inputbox" size="1" onchange="document.adminForm.submit();">
			<option value="all" '.$selected.'>All</option>';

	$qryalbum="select * from album";
	$selectalbum=$dbh->query($qryalbum);
	$nomor_urut=(($page_no-1)*$MAX);
	while($sqlRowalbum=mysql_fetch_object($selectalbum))
	{
		$nomor_urut++;
		$id_album=$sqlRowalbum->id_album;
		$nama_album=$sqlRowalbum->nama_album;
		if($id_album==$coll) 
		{ 
			$selected=' selected';
			$section=$sqlRowalbum->nama_album;
		} 
		else $selected='';
		$sort_album.='<option value="'.$id_album.'" '.$selected.'>'.$nama_album.'</option>';
	}
	if($section=='') $section='All';

	$sort_album.='</select>';
		
	$qry="select * from albumdetail $condition";
	$lim_min = ($page_no-1)*$MAX;
	$qry2="$qry limit $lim_min,$MAX"; 
	$select=$dbh->query($qry2);
	$TOTAL_RECORDSET=$dbh->num_rows($dbh->query($qry));

	$gallery_list='';
	$nomor_urut=(($page_no-1)*$MAX);
	while($sqlRow=mysql_fetch_object($select))
	{
	$nomor_urut++;
	$id_gallery=$sqlRow->id_gambar;
	$id_album=$sqlRow->id_album;
	$name=$sqlRow->nama_gambar;
	$deskripsi=$sqlRow->deskripsi;
	$thumbnail=$sqlRow->image;
	if ($thumbnail=='') $thumbnail='noimg.png';
	$thumbnail="<a href='admin.php?show=edit_gallery&id=$id_gallery&coll=$coll'><img border='0' width='75' height='56' src='assets/albumdetail/$thumbnail' /></a>";
	$gallery_list.='
		<tr class="row0">
			<td align="center">
				'.$nomor_urut.'
			</td>
			<td align="left">
				'.$thumbnail.'
			</td>
			<td>
				'.$name.'
			</td>
			<td align="center">
				<a href="admin.php?show=gallery_manager&action=do_delete&id='.$id_gallery.'" onclick="return confirm(\'Do you want to delete?\');"><img border="0" src="show_files/delete.png" /></a>
			</td>
			<td>
				'.$deskripsi.'
			</td>
		</tr>
	';
	}

}

//=====================Starting Pagination From Here==========================
	
	//global $my_page_name;
	$my_page_name="./admin.php?show=gallery_manager&coll=".$coll;
	include("admin_pagination.inc");

?>